﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Wicresoft.Framework.Organization;
using Wicresoft.Busi.BizLogic;
using Wicresoft.Busi.Entity;

public partial class RoomApplyInfo_Weektoputong : BaseNormalPage
{
    #region MeetingRoomGroups
    private DataTable MeetingRoomGroups
    {
        get
        {
            if (ViewState["MeetingRoomGroups"] != null)
                return (DataTable)ViewState["MeetingRoomGroups"];
            else
                return null;
        }
        set
        {
            ViewState["MeetingRoomGroups"] = value;
        }
    }
    #endregion

    #region bEdit
    private bool bEdit
    {
        get
        {
            if (ViewState["bEdit"] != null)
                return (bool)ViewState["bEdit"];
            else
                return false;
        }
        set
        {
            ViewState["bEdit"] = value;
        }
    }
    #endregion

    #region bSpecial
    private bool bSpecial
    {
        get
        {
            if (ViewState["bSpecial"] != null)
                return (bool)ViewState["bSpecial"];
            else
                return false;
        }
        set
        {
            ViewState["bSpecial"] = value;
        }
    }
    #endregion

    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //this.bEdit = OrganizationHelper.IsUserInRole(CurrentUser.ID, MeetingRoles.Apply);

            for (int i = DateTime.Today.Year - 3; i <= DateTime.Today.Year + 5; i++)
            {
                this.ddlYear.Items.Add(i.ToString());
            }
            this.ddlYear.SelectedIndex = 3;

            for (int i = 1; i <= 12; i++)
            {
                this.ddlMonth.Items.Add(i.ToString());
            }
            this.ddlMonth.SelectedIndex = DateTime.Today.Month - 1;

            //MeetingRoomGroups = BLMeetingRoomGroups.GetMeetingRoomGroups(BasePage.GetDept(CurrentUser.ID).ID);
        }

        LoadData();
    }

    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的.
        //
        InitializeComponent();
        base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容.
    /// </summary>
    private void InitializeComponent()
    {

    }
    #endregion

    private void LoadData()
    {
        //获取当天所在周的第一天
        DateTime dtTemp;
        if (Request.Form["txtDate"] == null || Request.Form["txtDate"].ToString() == "")
        {
            dtTemp = DateTime.Today;
            while (!dtTemp.DayOfWeek.ToString().Equals("Monday"))
                dtTemp = dtTemp.AddDays(-1);
        }
        else
            dtTemp = DateTime.Parse(Request.Form["txtDate"].ToString());

        initTable(dtTemp);
    }

    /// <summary>
    /// 获取会议室周使用信息
    /// </summary>
    /// <param name="dtTemp">周起始日</param>
    private void initTable(DateTime dtTemp)
    {
        String StartTime = dtTemp.ToString("yyyy-MM-dd");
        String EndTime = dtTemp.AddDays(7).ToString("yyyy-MM-dd");
        //String EndTime = dtTemp.AddDays(5).ToString("yyyy-MM-dd");

        string[] strRoomStatus = new string[] { RoomStatus.OPENED };
        DataTable dtRoom = BLMeetingRooms.GetMeetingRooms(strRoomStatus);

        string[] strMeetingStatus = new string[] { MeetingStatus.AUDIT };
        DataTable dtApply = BLMeetingRoomApply.GetMeetingRoomApply(strRoomStatus, strMeetingStatus, DateTime.Parse(StartTime), DateTime.Parse(EndTime));
        DrawMainTable(dtRoom, dtApply, dtTemp);
        this.txtDate.Text = dtTemp.ToString("yyyy-MM-dd");
    }

    /// <summary>
    /// 生成会议室周使用情况列表
    /// </summary>
    /// <param name="dtRoom">会议室信息</param>
    /// <param name="dtApply">会议室使用信息</param>
    /// <param name="dtTemp">周起始日</param>
    private void DrawMainTable(DataTable dtRoom, DataTable dtApply, DateTime dtTemp)
    {
        this.tbRoomApply.Controls.Clear();

        TableRow HeaderTR = new TableRow();
        for (int i = 0; i < 8; i++)
        //for (int i = 0; i < 6; i++)
        {
            TableCell HeaderTC = new TableCell();
            if (i == 0)
            {
                HeaderTC.ColumnSpan = 1;
                HeaderTC.RowSpan = 2;
                HeaderTC.Width = System.Web.UI.WebControls.Unit.Percentage(8);
                int iDay = dtTemp.Day;
                int iWeek, curMonth, curYear;
                if (dtTemp.Month != dtTemp.AddDays(6).Month)
                {
                    iWeek = iDay - 7 * (int)(iDay / 7);
                    if (iWeek > 1)
                        iWeek = (int)(iDay / 7) + 2;
                    else
                        iWeek = (int)(iDay / 7) + 1;
                    this.lblWeekNum.Text = dtTemp.Year + "年" + dtTemp.Month + "月 第" + iWeek + "周";

                    if (dtTemp.Month != 12)
                    {
                        curMonth = dtTemp.Month + 1;
                        this.lblWeekNum.Text += "(" + dtTemp.Year + "年" + curMonth + "月 第1周)";
                    }
                    else
                    {
                        curYear = dtTemp.Year + 1;
                        this.lblWeekNum.Text += "(" + curYear + "年1月 第1周)";
                    }
                }
                else
                {
                    iWeek = iDay - 7 * (int)(iDay / 7);
                    if (iWeek > 1)
                        iWeek = (int)(iDay / 7) + 2;
                    else
                        iWeek = (int)(iDay / 7) + 1;
                    this.lblWeekNum.Text = dtTemp.Year + "年" + dtTemp.Month + "月 第" + iWeek + "周";
                }
            }
            else
            {
                //HeaderTC.ColumnSpan = WebCommon.CoverCount;
                HeaderTC.Text = ConvertNumToWeek(i);
                HeaderTC.CssClass = "TableHeader";
            }
            HeaderTC.Width = Unit.Percentage(12.5);
            HeaderTR.Cells.Add(HeaderTC);
        }
        this.tbRoomApply.Rows.Add(HeaderTR);

        HeaderTR = new TableRow();
        for (int i = 0; i < 7; i++)
        //for (int i = 0; i < 5; i++)
        {
            TableCell HeaderTC = new TableCell();
            DateTime dtCurDate = dtTemp.AddDays(i).Date;
            //HeaderTC.ColumnSpan = WebCommon.CoverCount;
            HeaderTC.Text = "<a href=\"javascript:OpenWin('RoomApplyInfo_Day.aspx?Date=" + dtCurDate.ToString("yyyy-MM-dd") + "', '800', '600')\">" + dtCurDate.Month + "月" + dtCurDate.Day + "日";
            HeaderTC.BorderWidth = 1;
            HeaderTC.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
            HeaderTR.Cells.Add(HeaderTC);
        }
        this.tbRoomApply.Rows.Add(HeaderTR);

        HeaderTR = new TableRow();
        for (int i = 0; i < 7; i++)
        //for (int i = 0; i < 5; i++)
        {
            TableCell HeaderTC = new TableCell();
            HeaderTC.ColumnSpan = 1;
            HeaderTC.Width = System.Web.UI.WebControls.Unit.Percentage(4.5);
            HeaderTC.Text = "上午";
            HeaderTC.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
            HeaderTC.BorderWidth = 1;
            HeaderTR.Cells.Add(HeaderTC);
            HeaderTC = new TableCell();
            HeaderTC.ColumnSpan = 1;
            HeaderTC.Width = System.Web.UI.WebControls.Unit.Percentage(4.5);
            HeaderTC.Text = "下午";
            HeaderTC.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
            HeaderTC.BorderWidth = 1;
            HeaderTR.Cells.Add(HeaderTC);
            if (WebCommon.CoverCount == 3)
            {
                HeaderTC = new TableCell();
                HeaderTC.ColumnSpan = 1;
                HeaderTC.Width = System.Web.UI.WebControls.Unit.Percentage(4.5);
                HeaderTC.Text = "晚上";
                HeaderTC.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                HeaderTC.BorderWidth = 1;
                HeaderTR.Cells.Add(HeaderTC);
            }
        }
        //this.tbRoomApply.Rows.Add(HeaderTR);


        int RoomID;
        String RoomName, RoomInfo;
        int iShowLen = 20;
        String temp, tempTip;

        for (int i = 0; i < dtRoom.Rows.Count; i++)
        {
            TableRow TR = new TableRow();
            TR.Width = System.Web.UI.WebControls.Unit.Percentage(100);
            TableCell TC = new TableCell();
            TC.Width = System.Web.UI.WebControls.Unit.Percentage(7);
            TC.RowSpan = 1;
            TC.Height = 60;
            TC.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
            RoomID = int.Parse(dtRoom.Rows[i][vwMeetingRooms.SQLCOL_ID].ToString());
            RoomName = dtRoom.Rows[i][vwMeetingRooms.SQLCOL_ROOMNAME].ToString() + " <br>（座位数：" + dtRoom.Rows[i][vwMeetingRooms.SQLCOL_SEATSCOUNT].ToString() + "人）";
            RoomInfo = "类型：" + dtRoom.Rows[i][vwMeetingRooms.SQLCOL_ROOMTYPECN].ToString() + Environment.NewLine;

            RoomInfo += "名称：" + dtRoom.Rows[i][vwMeetingRooms.SQLCOL_ROOMNAME].ToString() + Environment.NewLine;
            RoomInfo += "位置：" + dtRoom.Rows[i][vwMeetingRooms.SQLCOL_LOCATION].ToString() + Environment.NewLine;
            RoomInfo += "座位数：" + dtRoom.Rows[i][vwMeetingRooms.SQLCOL_SEATSCOUNT].ToString() + Environment.NewLine;
            //RoomInfo += "描述："+ dtRoom.Rows[i][vwMeetingRooms.SQLCOL_DESCRIPTION].ToString() + Environment.NewLine;
            TC.Text = "<a href=\"JavaScript:OpenWin('RoomInfoView.aspx?ID=" + RoomID.ToString() + "', '600', '420');\">" + RoomName + "</a>";
            TC.ToolTip = RoomInfo;
            TC.Style.Add("cursor", "hand");
            TC.BorderWidth = 1;
            TC.CssClass = "Room";
            TR.Cells.Add(TC);

            for (int j = 0; j < 7; j++)
            //for (int j = 0; j < 5; j++)
            {
                for (int p = 0; p < 1; p++)//WebCommon.CoverCount; p++)
                {
                    if (WebCommon.CoverCount == 3)
                    {
                        if (p == 0)
                            dtApply.DefaultView.RowFilter = vwMeetingRoomApply.SQLCOL_ROOMID + " = " + RoomID.ToString() + " AND " + vwMeetingRoomApply.SQLCOL_MEETINGDATE + " = '" + dtTemp.AddDays(j).ToString("yyyy-MM-dd") + "' AND " + vwMeetingRoomApply.SQLCOL_CONVERTTIME + " = 0";
                        if (p == 1)
                            dtApply.DefaultView.RowFilter = vwMeetingRoomApply.SQLCOL_ROOMID + " = " + RoomID.ToString() + " AND " + vwMeetingRoomApply.SQLCOL_MEETINGDATE + " = '" + dtTemp.AddDays(j).ToString("yyyy-MM-dd") + "' AND " + vwMeetingRoomApply.SQLCOL_CONVERTTIME + " = 1";
                        if (p == 2)
                        {
                            dtApply.DefaultView.RowFilter = vwMeetingRoomApply.SQLCOL_ROOMID + " = " + RoomID.ToString() + " AND " + vwMeetingRoomApply.SQLCOL_MEETINGDATE + " = '" + dtTemp.AddDays(j).ToString("yyyy-MM-dd") + "' AND " + vwMeetingRoomApply.SQLCOL_CONVERTTIME + " = 3";
                            p = 3;
                        }
                    }
                    else
                    {
                        //if (p == 0)
                        //    dtApply.DefaultView.RowFilter = vwMeetingRoomApply.SQLCOL_ROOMID + " = " + RoomID.ToString() + " AND " + vwMeetingRoomApply.SQLCOL_MEETINGDATE + " = '" + dtTemp.AddDays(j).ToString("yyyy-MM-dd") + "' AND " + vwMeetingRoomApply.SQLCOL_CONVERTTIME + " = 0";
                        //if (p == 1)
                        dtApply.DefaultView.RowFilter = vwMeetingRoomApply.SQLCOL_ROOMID + " = " + RoomID.ToString() + " AND " + vwMeetingRoomApply.SQLCOL_MEETINGDATE + " = '" + dtTemp.AddDays(j).ToString("yyyy-MM-dd") + "' AND " + vwMeetingRoomApply.SQLCOL_CONVERTTIME + " in (0,1,3)";

                    }

                    if (dtApply.DefaultView.Count != 0)
                    {
                        #region 上午 下午 晚上
                        TC = new TableCell();
                        TC.Wrap = true;
                        TC.BorderWidth = 1;
                        TC.BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid;

                        Table tbCell = new Table();
                        tbCell.CssClass = "NoBorder";
                        tbCell.BorderWidth = 0;
                        tbCell.CellPadding = 2;
                        tbCell.CellSpacing = 0;
                        tbCell.Width = System.Web.UI.WebControls.Unit.Percentage(100);
                        tbCell.Height = System.Web.UI.WebControls.Unit.Percentage(100);
                        temp = "";
                        tempTip = "";

                        TableRow cTR;
                        TableCell cTC;
                        bool flag = true;
                        foreach (DataRowView rv in dtApply.DefaultView)
                        {
                            if (bEdit && dtTemp.AddDays(j) >= DateTime.Today && flag)
                            {
                                cTR = new TableRow();
                                cTC = new TableCell();
                                cTC.Font.Size = System.Web.UI.WebControls.FontUnit.Point(9);
                                //cTC.Height = System.Web.UI.WebControls.Unit.Percentage(100);
                                cTC.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
                                cTC.VerticalAlign = System.Web.UI.WebControls.VerticalAlign.Top;
                                //cTC.Text = "<a href=\"JavaScript:OpenDialog('ShowMessage.aspx?MsgType=1&ApplyID="+ rv[vwMeetingRoomApply.SQLCOL_ID].ToString() +"','400','380');\"><img src=\"../images/icon_add.gif\" border=\"0\"></a>";
                                //cTC.Text = "<a href=\"JavaScript:OpenWin('RoomApply.aspx?opener=InfoList&RoomID=" + RoomID.ToString() + "&Date=" + dtTemp.AddDays(j).ToString("yyyy-MM-dd") + "','800','600');\"><img src=\"../Images/icon_add.gif\" border=\"0\" /></a>";
                                cTR.Cells.Add(cTC);
                                tbCell.Rows.Add(cTR);
                                flag = false;
                            }

                            cTR = new TableRow();
                            cTC = new TableCell();
                            cTC.Font.Size = System.Web.UI.WebControls.FontUnit.Point(9);
                            cTC.Height = System.Web.UI.WebControls.Unit.Percentage(100 / dtApply.DefaultView.Count);
                            cTC.Style.Add("cursor", "hand");
                            cTC.VerticalAlign = VerticalAlign.Top;

                            if (rv[vwMeetingRoomApply.SQLCOL_TOPIC].ToString().Trim().Length > 8)
                                temp = rv[vwMeetingRoomApply.SQLCOL_TOPIC].ToString().Trim().Substring(0, 8) + "...";
                            else
                                temp = rv[vwMeetingRoomApply.SQLCOL_TOPIC].ToString().Trim();

                            tempTip = "会议名称：" + rv[vwMeetingRoomApply.SQLCOL_TOPIC].ToString().Trim() + Environment.NewLine;

                            tempTip += "会议时间：" + DateTime.Parse(rv[vwMeetingRoomApply.SQLCOL_MEETINGDATE].ToString()).ToString("yyyy-MM-dd") + rv[vwMeetingRoomApply.SQLCOL_CONVERTTIMECN].ToString() + rv[vwMeetingRoomApply.SQLCOL_STARTTIME].ToString() + Environment.NewLine;
                            tempTip += "参加人数：" + rv[vwMeetingRoomApply.SQLCOL_PEOPLECOUNT].ToString() + "人" + Environment.NewLine;
                            tempTip += "出席领导：" + rv[vwMeetingRoomApply.SQLCOL_REMARK1].ToString().Trim() + Environment.NewLine;
                            //tempTip += "服务套餐：" + rv[vwMeetingRoomApply.SQLCOL_REMARK2CN].ToString().Trim() + Environment.NewLine;
                            //tempTip += "申请部门：" + rv[vwMeetingRoomApply.SQLCOL_GROUPNAME].ToString().Trim() + Environment.NewLine;
                            tempTip += "联系人：" + rv[vwMeetingRoomApply.SQLCOL_APPLICANTNAME].ToString().Trim() + Environment.NewLine;
                            if (temp.Length > iShowLen)
                                temp = temp.Substring(0, iShowLen);
                            else
                                temp = temp.Trim();
                            DateTime MeetingStartTime = Convert.ToDateTime(rv[vwMeetingRoomApply.SQLCOL_MEETINGDATECN].ToString().Substring(0, rv[vwMeetingRoomApply.SQLCOL_MEETINGDATECN].ToString().LastIndexOf("-")));
                            //if ((this.bEdit && rv[vwMeetingRoomApply.SQLCOL_APPLICANT].ToString().Equals(CurrentUser.Name)
                            //    && rv[vwMeetingRoomApply.SQLCOL_STATUS].ToString().Equals(MeetingStatus.POST)) || (OrganizationHelper.IsUserInRole(CurrentUser.ID, MeetingRoles.Manage) && MeetingStartTime.CompareTo(DateTime.Now) > 0))
                            //    //	&& !dtRoom.Rows[i][vwMeetingRooms.SQLCOL_FLAG].ToString().Equals(RoomStatus.SPECIAL))
                            //    temp = "<a href=\"JavaScript:OpenWin('RoomApply.aspx?opener=InfoList&ApplyID=" + rv[vwMeetingRoomApply.SQLCOL_ID].ToString() + "', '800', '600');\">(" + rv[vwMeetingRoomApply.SQLCOL_MEETINGDATECN].ToString() + ")" + temp + "</a>";
                            //else
                                temp = "<a href=\"JavaScript:OpenWin('RoomApplyView1.aspx?UserType=view&ApplyID=" + rv[vwMeetingRoomApply.SQLCOL_ID].ToString() + "', '800', '600');\">(" + rv[vwMeetingRoomApply.SQLCOL_MEETINGDATECN].ToString() + ")" + temp + "</a>";

                            if (!rv[vwMeetingRoomApply.SQLCOL_REMARK2].ToString().Equals("1"))
                            {
                                cTC.BackColor = System.Drawing.Color.FromArgb(0xDDDDDD);
                            }
                            else
                            {
                                cTC.BackColor = System.Drawing.Color.FromArgb(0xFEFDCD);
                                cTC.Style.Add("cursor", "hand");
                            }

                            cTC.Text = temp;
                            cTC.ToolTip = tempTip;
                            cTR.Cells.Add(cTC);
                            tbCell.Rows.Add(cTR);
                            temp = "";
                        }

                        TC.Controls.Add(tbCell);
                        TR.Cells.Add(TC);
                        #endregion
                    }
                    else
                    {
                        dtApply.DefaultView.RowFilter = vwMeetingRoomApply.SQLCOL_ROOMID + " = " + RoomID.ToString() + " AND " + vwMeetingRoomApply.SQLCOL_MEETINGDATE + " = '" + dtTemp.AddDays(j).ToString("yyyy-MM-dd") + "' AND " + vwMeetingRoomApply.SQLCOL_CONVERTTIME + " = 2";
                        if (dtApply.DefaultView.Count != 0)
                        {
                            #region 全天
                            TC = new TableCell();
                            TC.Wrap = true;
                            TC.BorderWidth = 1;
                            TC.BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid;
                            TC.ColumnSpan = 3;

                            Table tbCell = new Table();
                            tbCell.CssClass = "NoBorder";
                            tbCell.BorderWidth = 0;
                            tbCell.CellPadding = 2;
                            tbCell.CellSpacing = 0;
                            tbCell.Width = System.Web.UI.WebControls.Unit.Percentage(100);
                            tbCell.Height = System.Web.UI.WebControls.Unit.Percentage(100);
                            temp = "";
                            tempTip = "";

                            TableRow cTR;
                            TableCell cTC;

                            foreach (DataRowView rv in dtApply.DefaultView)
                            {
                                if (bEdit && dtTemp.AddDays(j) > DateTime.Today)
                                {
                                    cTR = new TableRow();
                                    cTC = new TableCell();
                                    cTC.Font.Size = System.Web.UI.WebControls.FontUnit.Point(9);
                                    //cTC.Height = System.Web.UI.WebControls.Unit.Percentage(100);
                                    cTC.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
                                    cTC.VerticalAlign = System.Web.UI.WebControls.VerticalAlign.Top;
                                    //										if (dtRoom.Rows[i][vwMeetingRooms.SQLCOL_FLAG].ToString().Equals(RoomStatus.MAINTEMENT))
                                    //											cTC.Text = "<a href=\"JavaScript:OpenDialog('ShowMessage.aspx?MsgType=3', '400', '380');\"><img src=\"../images/icon_add.gif\" border=\"0\"></a>";
                                    //										else
                                    //cTC.Text = "<a href=\"JavaScript:OpenDialog('ShowMessage.aspx?MsgType=1&ApplyID=" + rv[vwMeetingRoomApply.SQLCOL_ID].ToString() + "', '400', '380');\"><img src=\"../Images/icon_add.gif\" border=\"0\" /></a>";
                                    cTR.Cells.Add(cTC);
                                    tbCell.Rows.Add(cTR);
                                }

                                cTR = new TableRow();
                                cTC = new TableCell();
                                cTC.Font.Size = System.Web.UI.WebControls.FontUnit.Point(9);
                                cTC.Height = System.Web.UI.WebControls.Unit.Percentage(100);
                                cTC.Style.Add("cursor", "hand");
                                cTC.VerticalAlign = VerticalAlign.Top;

                                if (rv[vwMeetingRoomApply.SQLCOL_TOPIC].ToString().Trim().Length > 10)
                                    temp = rv[vwMeetingRoomApply.SQLCOL_TOPIC].ToString().Trim().Substring(0, 10) + "...";
                                else
                                    temp = rv[vwMeetingRoomApply.SQLCOL_TOPIC].ToString().Trim();

                                tempTip = "会议名称：" + rv[vwMeetingRoomApply.SQLCOL_TOPIC].ToString().Trim() + Environment.NewLine;

                                tempTip += "会议时间：" + DateTime.Parse(rv[vwMeetingRoomApply.SQLCOL_MEETINGDATE].ToString()).ToString("yyyy-MM-dd") + rv[vwMeetingRoomApply.SQLCOL_CONVERTTIMECN].ToString() + rv[vwMeetingRoomApply.SQLCOL_STARTTIME].ToString() + Environment.NewLine;
                                tempTip += "参加人数：" + rv[vwMeetingRoomApply.SQLCOL_PEOPLECOUNT].ToString() + "人" + Environment.NewLine;
                                tempTip += "出席领导：" + rv[vwMeetingRoomApply.SQLCOL_REMARK1].ToString().Trim() + Environment.NewLine;
                                //tempTip += "服务套餐：" + rv[vwMeetingRoomApply.SQLCOL_REMARK2CN].ToString().Trim() + Environment.NewLine;
                                //tempTip += "申请部门：" + rv[vwMeetingRoomApply.SQLCOL_GROUPNAME].ToString().Trim() + Environment.NewLine;
                                tempTip += "联系人：" + rv[vwMeetingRoomApply.SQLCOL_APPLICANTNAME].ToString().Trim() + Environment.NewLine;
                                if (temp.Length > iShowLen)
                                    temp = temp.Substring(0, iShowLen);
                                else
                                    temp = temp.Trim();
                                DateTime MeetingStartTime = Convert.ToDateTime(rv[vwMeetingRoomApply.SQLCOL_MEETINGDATECN].ToString().Substring(0, rv[vwMeetingRoomApply.SQLCOL_MEETINGDATECN].ToString().LastIndexOf("-")));
                                //if ((this.bEdit && rv[vwMeetingRoomApply.SQLCOL_APPLICANT].ToString().Equals(CurrentUser.Name)
                                //    && rv[vwMeetingRoomApply.SQLCOL_STATUS].ToString().Equals(MeetingStatus.POST)) || (OrganizationHelper.IsUserInRole(CurrentUser.ID, MeetingRoles.Manage) && MeetingStartTime.CompareTo(DateTime.Now) > 0))
                                //    //	&& !dtRoom.Rows[i][vwMeetingRooms.SQLCOL_FLAG].ToString().Equals(RoomStatus.SPECIAL))
                                //    temp = "<a href=\"JavaScript:OpenWin('RoomApply.aspx?opener=InfoList&ApplyID=" + rv[vwMeetingRoomApply.SQLCOL_ID].ToString() + "', '800', '600');\">(" + rv[vwMeetingRoomApply.SQLCOL_MEETINGDATECN].ToString() + ")" + temp + "</a>";
                                //else
                                    temp = "<a href=\"JavaScript:OpenWin('RoomApplyView1.aspx?UserType=view&ApplyID=" + rv[vwMeetingRoomApply.SQLCOL_ID].ToString() + "', '800', '600');\">(" + rv[vwMeetingRoomApply.SQLCOL_MEETINGDATECN].ToString() + ")" + temp + "</a>";

                                if (!rv[vwMeetingRoomApply.SQLCOL_STATUS].ToString().Equals(MeetingStatus.AUDIT))
                                {
                                    TC.BackColor = System.Drawing.Color.FromArgb(0xDDDDDD);
                                }
                                else
                                {
                                    TC.BackColor = System.Drawing.Color.FromArgb(0xFEFDCD);
                                    TC.Style.Add("cursor", "hand");
                                }

                                cTC.Text = temp;
                                cTC.ToolTip = tempTip;
                                cTR.Cells.Add(cTC);
                                tbCell.Rows.Add(cTR);
                                temp = "";
                            }

                            TC.Controls.Add(tbCell);
                            TR.Cells.Add(TC);
                            #endregion
                            p = 2;
                        }
                        else
                        {
                            TC = new TableCell();
                            if (dtTemp.AddDays(j) > DateTime.Today || dtTemp.AddDays(j) == DateTime.Today)//&& (p == 0 && DateTime.Now.Hour < 12 || p == 1 && DateTime.Now.Hour < 18 || p == 3 && DateTime.Now.Hour < 24)))
                            {
                                TC.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
                                TC.VerticalAlign = System.Web.UI.WebControls.VerticalAlign.Top;
                                //TC.Text = "<a href=\"JavaScript:OpenWin('RoomApply.aspx?opener=InfoList&RoomID=" + RoomID.ToString() + "&Date=" + dtTemp.AddDays(j).ToString("yyyy-MM-dd") + "&time=" + p + "', '800', '600');\"><img src=\"../Images/icon_add.gif\" border=\"0\" /></a>";

                            }
                            TC.Wrap = true;
                            TC.BorderWidth = 1;
                            TC.BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid;
                            TR.Cells.Add(TC);
                        }
                    }
                }
            }
            TR.BorderWidth = 1;
            this.tbRoomApply.Rows.Add(TR);
        }
    }

    /// <summary>
    /// 把数字转换成星期
    /// </summary>
    /// <param name="Num">数字</param>
    /// <returns>星期</returns>
    private String ConvertNumToWeek(int Num)
    {
        switch (Num)
        {
            case 1: return "星期一";
            case 2: return "星期二";
            case 3: return "星期三";
            case 4: return "星期四";
            case 5: return "星期五";
            case 6: return "星期六";
            case 7: return "星期日";
            default: return null;
        }
    }

    /// <summary>
    /// 把星期转换成数字
    /// </summary>
    /// <param name="Week">星期</param>
    /// <returns>数字</returns>
    private int ConvertWeekToNum(String Week)
    {
        switch (Week)
        {
            case "Monday": return 0;
            case "Tuesday": return 1;
            case "Wendesday": return 2;
            case "Thursday": return 3;
            case "Friday": return 4;
            case "Saturday": return 5;
            case "Sunday": return 6;
            default: return -1;
        }
    }

    protected void btnLastWeek_Click(object sender, System.EventArgs e)
    {
        DateTime Date = DateTime.Parse(this.txtDate.Text);
        Date = Date.AddDays(-7);

        initTable(Date);
    }

    protected void btnNextWeek_Click(object sender, System.EventArgs e)
    {
        DateTime Date = DateTime.Parse(this.txtDate.Text);
        Date = Date.AddDays(7);

        initTable(Date);
    }

    protected void ddlYear_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        DateTime Date = new DateTime(int.Parse(this.ddlYear.SelectedItem.Text), int.Parse(this.ddlMonth.SelectedItem.Text), 1);
        while (!Date.DayOfWeek.ToString().Equals("Monday"))
            Date = Date.AddDays(-1);

        initTable(Date);
    }

    protected void btnCurWeek_Click(object sender, System.EventArgs e)
    {
        DateTime dtTemp = DateTime.Today;
        while (!dtTemp.DayOfWeek.ToString().Equals("Monday"))
            dtTemp = dtTemp.AddDays(-1);
        initTable(dtTemp);
    }
}
